package presentationTier.actions;

import businessTier.IMovieFacade;
import businessTier.MovieFacade;
import core.Genre;
import core.Medium;
import core.Movie;
import core.MovieException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import presentationTier.Global;
import presentationTier.MainForm;
import presentationTier.dialogs.ChangeMovieDialog;

/**
 *
 * @author vojta
 */
public class ChangeMovieOkAction implements ActionListener{

    ChangeMovieDialog dialog;

    public ChangeMovieOkAction(ChangeMovieDialog aThis) {
        dialog = aThis;
    }

    public void actionPerformed(ActionEvent e) {
        try {
            Movie movie = dialog.getMovie();
            movie.setName(dialog.txtName.getText());
            movie.setDirector(dialog.txtDirector.getText());
            movie.setYear(Integer.parseInt(dialog.txtYear.getText()));
            movie.setMedium((Medium) dialog.comboBoxMedium.getSelectedItem());
            movie.setGenre((Genre) dialog.comboBoxGenre.getSelectedItem());
            IMovieFacade mf = MovieFacade.getInstance();
            mf.changeMovie(movie);

            MainForm form = (MainForm) dialog.getParent();
            Global.refreshTable(form);

            dialog.dispose();

        } catch (MovieException ex) {
            ex.printStackTrace();
        }


    }

}
